const CopyWebpackPlugin = require('copy-webpack-plugin');
const URL = require('../vue-common/lib/url2');

const path = require('path');

function resolve(dir) {
    return path.resolve(__dirname, dir);
}

var config_resolve = {
    extensions: ['.js', '.vue', '.json', '.ts'],
    alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': resolve('src'),
        '@common': resolve('../vue-common'),
    }
}

var config;
if(process.env.NODE_ENV === 'production') {
    config = {
        outputDir: URL.outputDir + "/index",
        assetsDir: "../index_static",
        configureWebpack: config => {
            return {
                plugins:[
                    new CopyWebpackPlugin([{
                        from:'node_modules/@aspnet/signalr/dist/browser/signalr.min.js'
                    },{
                        from:'node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.signalr-client.js'
                    },{
                        from:'src/lib/abp.js'
                    }])
                ],
                resolve: config_resolve
            }
        },
        // chainWebpack: config => {
        //     config.module
        //         .rule('iview')
        //         .test(/iview.src.*?js$/)
        //         .use('babel')
        //         .loader('babel-loader')
        //         .end();
        // }
    };
}else {
    config = {
        configureWebpack: config => {
            return {
                plugins:[
                    new CopyWebpackPlugin([{
                        from:'node_modules/@aspnet/signalr/dist/browser/signalr.min.js',
                        //to:'dist'
                    },{
                        from:'node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.signalr-client.js',
                        //to:'dist'
                    },{
                        from:'src/lib/abp.js',
                        //to:'dist'
                    }])
                ],
                devServer: {
                    proxy: {
                        '/resource/': {
                            target: URL.remoteUrl,
                            ws: true,
                            changeOrigin: true
                        }
                    }
                },
                resolve: config_resolve
            }
        }
    };
}

module.exports = config;